package com.syj.collect.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.syj.collect.app.R;
import com.syj.collect.entry.Mymonth;
import com.syj.collect.model.MyMonthActivity;

import java.util.ArrayList;
import java.util.List;

public  class MyMonthAdapter extends RecyclerView.Adapter<MyMonthAdapter.MonthHoder> {
    private Context context;
    private List<Mymonth.DataDTO.ListDTO> list;
    public MyMonthAdapter(Context myMonthActivity) {
        this.context=myMonthActivity;
        list=new ArrayList<>();
    }

    public interface OnItemClickListener {
        void onClick(String url);
    }

    private OnItemClickListener listener;


    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }





    @NonNull
    @Override
    public MyMonthAdapter.MonthHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_collect,parent,false);
        return new MonthHoder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyMonthAdapter.MonthHoder holder, int position) {
        holder.ll_layout.setVisibility(View.GONE);
        holder.tv_conent.setVisibility(View.GONE);
        holder.tv_title.setText(list.get(position).getName());
        holder.tv_data.setText(list.get(position).getCreateDate());
        holder.ll_month.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onClick(list.get(position).getUrl());
                }
            }
        });
        }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addList(List<Mymonth.DataDTO.ListDTO> listdata) {
        list.addAll(listdata);
        notifyDataSetChanged();
    }

    public class MonthHoder extends RecyclerView.ViewHolder {
        ImageView iv_left;
        TextView tv_title;
        TextView tv_conent;
        TextView tv_data;
        LinearLayout ll_layout;
        LinearLayout ll_month;
        public MonthHoder(@NonNull View itemView) {
            super(itemView);
            iv_left=itemView.findViewById(R.id.iv_left);
            tv_title=itemView.findViewById(R.id.tv_title);
            tv_conent=itemView.findViewById(R.id.tv_conent);
            tv_data=itemView.findViewById(R.id.tv_data);
            ll_layout=itemView.findViewById(R.id.ll_layout);
            ll_month=itemView.findViewById(R.id.ll_month);
        }
    }
}
